package com.mofang.powerdekorhelper.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;


/**
 * Sharedperference工具类
 *
 * @author luofei
 */
public class SharePerforenceUtils {
    private static SharePerforenceUtils sharedUtile = null;
    public static SharedPreferences mPreferences;
    public Editor mEditor;

    private static Context mContext;

    public static SharePerforenceUtils getInstance(Context context) {
        mContext = context;
        if (sharedUtile == null) {
            sharedUtile = new SharePerforenceUtils();
        }
        return sharedUtile;
    }

    public SharePerforenceUtils() {
        mPreferences = mContext.getSharedPreferences(Constants.SHARE_NAME, Context.MODE_PRIVATE);
        mEditor = mPreferences.edit();
    }

    /**
     * 是否登陆
     *
     * @return
     */
    public boolean getLogin() {
        return mPreferences.getBoolean(Constants.IS_LOGIN, false);
    }

    public void setLogin(boolean isLogin) {
        mEditor.putBoolean(Constants.IS_LOGIN, isLogin);
        mEditor.commit();
    }

    /**
     * 获取用户ID
     *
     * @return
     */
    public int getUserID() {
        return mPreferences.getInt(Constants.SHARE_USER_ID, -1);
    }

    public void setUserID(Integer userid) {
        mEditor.putInt(Constants.SHARE_USER_ID, userid);
        mEditor.commit();
    }

    /**
     * 保存账号
     */
    public String getUserName() {
        return mPreferences.getString(Constants.SHARE_USER_ACCOUNT, "");
    }

    public void setUserName(String userName) {
        mEditor.putString(Constants.SHARE_USER_ACCOUNT, userName);
        mEditor.commit();
    }

    /**
     * 保存名称
     */
    public String getName() {
        return mPreferences.getString(Constants.SHARE_USER_NAME, "");
    }

    public void setName(String userName) {
        mEditor.putString(Constants.SHARE_USER_NAME, userName);
        mEditor.commit();
    }

    /**
     * 保存电话
     */
    public String getPhone() {
        return mPreferences.getString(Constants.SHARE_USER_BIND_PHONE, "");
    }

    public void setPhone(String phone) {
        mEditor.putString(Constants.SHARE_USER_BIND_PHONE, phone);
        mEditor.commit();
    }

    /**
     * 保存店铺ID
     */
    public int getShopId() {
        return mPreferences.getInt(Constants.SHARE_SHOP_ID, -1);
    }

    public void setShopId(int shopId) {
        mEditor.putInt(Constants.SHARE_SHOP_ID, shopId);
        mEditor.commit();
    }

    /**
     * 保存集团ID
     */
    public String getNodeId() {
        return mPreferences.getString(Constants.SHARE_NODE_ID, "");
    }

    public void setNodeId(String nodeId) {
        mEditor.putString(Constants.SHARE_NODE_ID, nodeId);
        mEditor.commit();
    }

    /**
     * 保存集团logo
     */
    public String getNode3Image() {
        return mPreferences.getString(Constants.SHARE_NODE3_Image, "");
    }

    public void setNode3Image(String nodeImage) {
        mEditor.putString(Constants.SHARE_NODE3_Image, nodeImage);
        mEditor.commit();
    }

    /**
     * 保存厂家ID
     */
    public int getFactoryId() {
        return mPreferences.getInt(Constants.SHARE_FACTORY_ID, -1);
    }

    public void setFactoryId(Integer factoryId) {
        mEditor.putInt(Constants.SHARE_FACTORY_ID, factoryId);
        mEditor.commit();
    }

    /**
     * 保存所属公司名称
     */
    public String getBelongCompany() {
        return mPreferences.getString(Constants.SHARE_COMPANY_NAME, "");
    }

    public void setBelongCompany(String company) {
        mEditor.putString(Constants.SHARE_COMPANY_NAME, company);
        mEditor.commit();
    }

    /**
     * 保存regionCode
     */
    public String getAdCode() {
        return mPreferences.getString(Constants.ADCODE_ID, "");
    }

    public void setAdCode(String adCode) {
        mEditor.putString(Constants.ADCODE_ID, adCode);
        mEditor.commit();
    }

    /**
     * 经度
     *
     * @return
     */
    public String getLongitude() {
        return mPreferences.getString(Constants.LONGITUDE_ID, "0.0");
    }

    public void setLongitude(String longitude) {
        mEditor.putString(Constants.LONGITUDE_ID, longitude);
        mEditor.commit();
    }


    /**
     * 纬度
     *
     * @return
     */
    public String getLatitude() {
        return mPreferences.getString(Constants.LATITUDE_ID, "0.0");
    }

    public void setLatitude(String latitude) {
        mEditor.putString(Constants.LATITUDE_ID, latitude);
        mEditor.commit();
    }


}
